package com.example.watson.myworkmanager

import android.util.Log

object Logger {
    private val TAG = "ch-log--"
    private val LOG_ENABLE = true
    private val DETAIL_ENABLE = true

    private fun buildMsg(msg: String): String {
        val buffer = StringBuilder()

        if (DETAIL_ENABLE) {
            val stackTraceElement = Thread.currentThread().stackTrace[4]

            buffer.append("[T:")
            buffer.append(Thread.currentThread().name)
            buffer.append(" F:")
            buffer.append(stackTraceElement.fileName)
            buffer.append(" L:")
            buffer.append(stackTraceElement.lineNumber)
            buffer.append(" M:")
            buffer.append(stackTraceElement.methodName)
            buffer.append("()]--")
        }
        buffer.append(msg)
        return buffer.toString()

    }

    fun v(msg: String) {
        if (LOG_ENABLE) {
            Log.v(TAG, buildMsg(msg))
        }
    }

    fun v(TAG: String, msg: String) {
        if (LOG_ENABLE) {
            Log.v(TAG, buildMsg(msg))
        }
    }

    fun d(msg: String) {
        if (LOG_ENABLE) {
            Log.d(TAG, buildMsg(msg))
        }
    }

    fun d(TAG: String, msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.DEBUG)) {
        if (LOG_ENABLE) {
            Log.d(TAG, buildMsg(msg))
        }
    }

    fun i(msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.INFO)) {
        if (LOG_ENABLE) {
            Log.i(TAG, buildMsg(msg))
        }
    }

    fun i(TAG: String, msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.INFO)) {
        if (LOG_ENABLE) {
            Log.i(TAG, buildMsg(msg))
        }
    }

    fun w(msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.WARN)) {
        if (LOG_ENABLE) {
            Log.w(TAG, buildMsg(msg))
        }
    }

    fun w(TAG: String, msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.WARN)) {
        if (LOG_ENABLE) {
            Log.w(TAG, buildMsg(msg))
        }
    }

    fun w(msg: String, e: Exception) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.WARN)) {
        if (LOG_ENABLE) {
            Log.w(TAG, buildMsg(msg), e)
        }
    }

    fun w(TAG: String, msg: String, e: Exception) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.WARN)) {
        if (LOG_ENABLE) {
            Log.w(TAG, buildMsg(msg), e)
        }
    }

    fun e(msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.ERROR)) {
        if (LOG_ENABLE) {
            Log.e(TAG, buildMsg(msg))
        }
    }

    fun e(TAG: String, msg: String) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.ERROR)) {
        if (LOG_ENABLE) {
            Log.e(TAG, buildMsg(msg))
        }
    }

    fun e(msg: String, e: Exception) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.ERROR)) {
        if (LOG_ENABLE) {
            Log.e(TAG, buildMsg(msg), e)
        }
    }

    fun e(TAG: String, msg: String, e: Exception) {
        // if (LOG_ENABLE && Log.isLoggable(TAG, Log.ERROR)) {
        if (LOG_ENABLE) {
            Log.e(TAG, buildMsg(msg), e)
        }
    }
}
